home *** CD-ROM | disk | FTP | other *** search
- /* Contains the equation compiler */
-
- #include <ctype.h>
- #include <SANE.h>
- #include "EqnCompiler.h"
-
- /* Global Variables */
- static int **codeBlock; /* handle to code */
- static char *textPtr; /* ptr to eqn text */
- static int textLen; /* length of eqn text */
- static char mode; /* text scan mode */
- static int *textIndex; /* current scan posn */
- static int codeIndex; /* current write posn */
- static int frameIndex; /* stack frame posn */
- static int frameSize; /* stack frame size */
- extern ProcPtr CFPtr[]; /* custom func ptrs */
-
- int CompileEqn(void *textBuff, int length, int *index, Handle codeHand)
- {
- int level=0; /* parenthesis level */
- int operand=0; /* current operand type */
- int offset; /* coeff offset from array ptr */
- long operation[MAX_PENDING]; /* stored operns */
- int opIndex=0; /* next posn in operation[] */
- int result, error;
- extended num;
-
- /* re-initialize globals */
- codeBlock = (int **) codeHand;
- textPtr = textBuff;
- textIndex = index;
- textLen = length;
- frameIndex = 0;
- frameSize = 0;
- mode = OPERAND_SCAN;
-
- SetHandleSize(codeBlock, 0); /* zero code blk */
- if (MemError()) return memoryErr;
-
- /* get first char, ignore white space chars */
- while (isspace(*(textPtr+*textIndex)) && *textIndex<textLen)
- (*textIndex)++;
- if (*textIndex>=textLen || *(textPtr+*textIndex)==';')
- return nullEqnErr;
-
- /* code for setting up a stack frame */
- codeIndex = 2;
- SetHandleSize(codeBlock, 4);
- if (MemError()) return memoryErr;
- **codeBlock = 0x4E56; /* link A6,#-__ ; (fill in size of frame later) */
-
- while (true) {
- if (mode == OPERAND_SCAN) {
- /* scan for operand or unary function */
- if ((*(textPtr+*textIndex)=='.') || isdigit(*(textPtr+*textIndex))) {
- /* scan for numeric constant */
- if (operand) {
- /* copy old operand to frame */
- error = OperandCode(operand, offset, &num);
- if (error) return error;
- }
- error = ScanNum(&num);
- if (error) return error;
- operand = CONST_OPERAND;
- } else {
- /* scan for operand or unary function */
- error = ScanFn(&result);
- if (error) return error;
- switch (result & 0xF000) {
- case PARENTH: /* ( */
- level++; /* inc parenth level */
- break;
- case X_OPERAND: /* x */
- case COEFF_OPERAND: /* a, b, c … */
- case PI_OPERAND: /* π */
- if (operand) {
- /* copy old operand to frame */
- error = OperandCode(operand, offset, &num);
- if (error) return error;
- }
- operand = result & 0xF000;
- if (operand == PI_OPERAND) num = pi();
- else if (operand == COEFF_OPERAND)
- offset = result & 0x00FF;
- break;
- case UN_MINUS: /* unary minus */
- case UN_FUNC: /* unary function */
- opIndex++;
- if (opIndex > MAX_PENDING)
- return tooManyOpErr;
- /* add operation to queue */
- operation[opIndex-1] = level*0x10000 + result;
- if ((result & 0xF000) != UN_MINUS)
- level++; /* inc parenth level */
- }
- }
- } else if (mode == OPERATOR_SCAN) {
- /* scan for binary operator */
- error = ScanOp(&result);
- if (error) return error;
- if (result) { /* found operator */
- opIndex++;
- if (opIndex > MAX_PENDING)
- return tooManyOpErr;
- /* add operation to queue */
- operation[opIndex-1] = level*0x10000 + result;
- } else { /* ')' */
- level--; /* decrement parenth level */
- if (level < 0) return unbalParenErr;
- }
- }
- /* compact pending operation array */
- while (opIndex > 1) {
- if ((operation[opIndex-1]&RANK) <= (operation[opIndex-2]&RANK)) {
- /* add opern to code */
- error = OperationCode(operation[opIndex-2], operand, offset, &num);
- if (error) return error;
- operand = 0;
- /* remove operation from queue */
- operation[opIndex-2] = operation[opIndex-1];
- opIndex--;
- } else break;
- }
- /* get next token, ignore white space chars */
- while (isspace(*(textPtr+*textIndex)) && *textIndex<textLen)
- (*textIndex)++;
- if (*textIndex>=textLen || *(textPtr+*textIndex)==';') {
- if (mode==OPERAND_SCAN)
- return noOperandErr;
- else break;
- }
- }
-
- /* add pending operations to code */
- while (opIndex > 0) {
- error = OperationCode(operation[opIndex-1], operand, offset, &num);
- if (error) return error;
- operand = 0;
- opIndex--; /* remove opern from queue */
- }
-
- if (level) return unbalParenErr;
- /* set frame size of initial link instrn */
- *(*codeBlock+1) = -10*frameSize;
-
- /* code for return value */
- if (operand) error = ReturnCode1(operand, offset, &num);
- else error = ReturnCode2();
- if (error) return error;
- codeIndex += 2; /* unlink and rts code */
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- *(*codeBlock+codeIndex-2)=0x4E5E; /* unlk A6 */
- *(*codeBlock+codeIndex-1)=0x4E75; /* rts */
- return 0;
- }
-
- /* scan the text for a number */
- int ScanNum(extended *num)
- {
- int i=0;
- Boolean valid;
- char str[MAX_CONST_LEN+1]; /* C str */
- short index;
- decimal dec;
-
- do { /* find longest valid numeric string */
- if (i>=MAX_CONST_LEN) return longNumErr;
- str[i] = *(textPtr+*textIndex+i);
- str[i+1] = 0; /* NULL terminator */
- index = 0;
- cstr2dec(str, &index, &dec, &valid);
- if (!valid) break;
- i++;
- if (*textIndex+i>=textLen || *(textPtr+*textIndex+i)==';') break;
- } while (valid);
-
- if (!index) return badNumErr;
- *num = dec2num(&dec);
- if (classextended(*num)<3 && classextended(*num)>-3)
- return badNumErr; /* NAN, INF */
- *textIndex += index;
- mode = OPERATOR_SCAN;
- return 0;
- }
-
- /* scan text for operand or function */
- int ScanFn(int *result)
- {
- char str[MAX_KWORD_LEN+1]; /* pascal str */
- int error, i=0;
-
- /* get longest alphabetic substring */
- while (isalpha(*(textPtr+*textIndex+i))) {
- if (i>MAX_KWORD_LEN) return badTokenErr;
- str[i+1] = *(textPtr+*textIndex+i);
- i++;
- if (*textIndex+i>=textLen || *(textPtr+*textIndex+i)==';') break;
- }
-
- str[0] = i; /* length byte */
- switch (i) {
- /* match string against expected strings */
- case 0: /* first char was not alphabetic */
- if (*(textPtr+*textIndex) == '-')
- /* unary minus */
- *result = UN_MINUS+FP68K+(FNEGX&0x00FF);
- else if (*(textPtr+*textIndex) == '(')
- *result = PARENTH; /* '(' */
- else if (*(textPtr+*textIndex) == 'π' || *(textPtr+*textIndex) == '∏') {
- *result = PI_OPERAND; /* pi */
- mode = OPERATOR_SCAN;
- } else return noOperandErr;
- (*textIndex)++;
- return 0;
- case 1: /* single alphabetic character */
- if (tolower(str[1]) >= 'a' && tolower(str[1]) <= 'e') { /* coefficient */
- switch (tolower(str[1])) {
- case 'a':
- *result = COEFF_OPERAND;
- break;
- case 'b':
- *result = COEFF_OPERAND + 10;
- break;
- case 'c':
- *result = COEFF_OPERAND + 20;
- break;
- case 'd':
- *result = COEFF_OPERAND + 30;
- break;
- case 'e':
- *result = COEFF_OPERAND + 40;
- }
- } else if (tolower(str[1]) == 'x')
- *result = X_OPERAND; /* x */
- else goto lookup; /* custom func? */
- (*textIndex)++;
- mode = OPERATOR_SCAN;
- return 0;
- case 2: /* two alphabetic characters */
- if (EqualString(str, "\ppi", false, true))
- *result = PI_OPERAND; /* pi */
- else goto lookup; /* custom func? */
- *textIndex += 2;
- mode = OPERATOR_SCAN;
- return 0;
- case 3: /* three alphabetic characters */
- if (EqualString(str, "\psin", 0, 1))
- *result = UN_FUNC+ELEMS68K+(FSINX&0x00FF);
- else if (EqualString(str, "\pcos", 0, 1))
- *result = UN_FUNC+ELEMS68K+(FCOSX&0x00FF);
- else if (EqualString(str, "\ptan", 0, 1))
- *result = UN_FUNC+ELEMS68K+(FTANX&0x00FF);
- else if (EqualString(str, "\plog", 0, 1))
- *result = UN_FUNC+ELEMS68K+(FLNX&0x00FF);
- else if (EqualString(str, "\pexp", 0, 1))
- *result = UN_FUNC+ELEMS68K+(FEXPX&0x00FF);
- else goto lookup; /* custom func? */
- break;
- case 4: /* four alphabetic characters */
- if (EqualString(str, "\psqrt", 0, 1))
- *result = UN_FUNC+FP68K+(FSQRTX&0x00FF);
- else if (EqualString(str, "\patan", 0, 1))
- *result = UN_FUNC+ELEMS68K+(FATANX&0x00FF);
- else goto lookup; /* custom func? */
- break;
- default: /* other string lengths */
- lookup: /* custom func? */
- error = LookUpCF(str, result);
- if (error) return error;
- }
-
- /* check next char is '(' */
- while (isspace(*(textPtr+*textIndex+i)) && *textIndex+i<textLen) i++;
- if (*textIndex+i>=textLen || *(textPtr+*textIndex+i)==';' || *(textPtr+*textIndex+i)!='(')
- return noLeftParenErr;
- *textIndex += i+1;
- return 0;
- }
-
- /* scan text for an operator */
- int ScanOp(int *result)
- {
- switch (*(textPtr+*textIndex)) {
- case '+': /* addition */
- *result = PRIORITY_1+FP68K+(FADDX&0x00FF);
- break;
- case '-': /* subtraction */
- *result = PRIORITY_1+FP68K+(FSUBX&0x00FF);
- break;
- case '*': /* multiplication */
- *result = PRIORITY_2+FP68K+(FMULX&0x00FF);
- break;
- case '/': /* division */
- *result = PRIORITY_2+FP68K+(FDIVX&0x00FF);
- break;
- case '^': /* exponentiation */
- *result = EXPONENT+ELEMS68K+(FXPWRY&0x00FF);
- break;
- case ')': /* end of parenthesis */
- *result = PARENTH;
- break;
- default: /* syntax error */
- return noOperatorErr;
- }
-
- /* don't change mode if ')' encountered */
- if (*result != PARENTH) mode = OPERAND_SCAN;
- (*textIndex)++;
- return 0;
- }
-
- /* classify operation, call handler routines */
- int OperationCode(int operation, int operand, int offset, extended *numPtr)
- {
- int error;
-
- if ((operation&0xF000) == UN_MINUS || (operation&0xF000) == UN_FUNC) {
- /* unary operation */
- if (operand) {
- error = OperandCode(operand, offset, numPtr);
- if (error) return error;
- }
- error = UnOpCode(operation);
- if (error) return error;
- } else {
- /* binary operation */
- if (operand == X_OPERAND || operand == COEFF_OPERAND) {
- error = BinOpCode1(operation, operand, offset);
- if (error) return error;
- } else {
- if (operand == CONST_OPERAND) {
- error = OperandCode(CONST_OPERAND, 0, numPtr);
- if (error) return error;
- }
- error = BinOpCode2(operation);
- if (error) return error;
- }
- }
- return 0;
- }
-
- /* set up code for copying operand into stack frame */
- int OperandCode(int operand, int offset, extended *numPtr)
- {
- frameIndex++;
- if (frameIndex>frameSize) frameSize=frameIndex;
- if (operand == X_OPERAND) {
- codeIndex += 7;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* lea.l -10fi(A6),A0; A0 <- frame_adr */
- *(*codeBlock+codeIndex-7) = 0x41EE;
- *(*codeBlock+codeIndex-6) = -10*frameIndex;
- /* lea.l 12(A6),A1; A1 <- x_adr */
- *(*codeBlock+codeIndex-5) = 0x43EE;
- *(*codeBlock+codeIndex-4) = 0x000C;
- /* move.l (A1)+,(A1)+; copy x into frame */
- *(*codeBlock+codeIndex-3) = 0x20D9;
- /* move.l (A1)+,(A1)+ */
- *(*codeBlock+codeIndex-2) = 0x20D9;
- /* move.w (A1)+,(A1)+ */
- *(*codeBlock+codeIndex-1) = 0x30D9;
- } else if (operand == COEFF_OPERAND) {
- codeIndex += 2;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l 22(A6),A0; A0 <- coeff base adr */
- *(*codeBlock+codeIndex-2) = 0x206E;
- *(*codeBlock+codeIndex-1) = 0x0016;
- if (offset) {
- codeIndex += 3;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l off(A0),-10fi(A6); copy coeff */
- *(*codeBlock+codeIndex-3) = 0x2D68;
- *(*codeBlock+codeIndex-2) = offset;
- *(*codeBlock+codeIndex-1) = -10*frameIndex;
- } else {
- codeIndex += 2;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l (A0),-10fi(A6); copy coeff */
- *(*codeBlock+codeIndex-2) = 0x2D50;
- *(*codeBlock+codeIndex-1) = -10*frameIndex;
- }
- codeIndex += 6;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l off+4(A0),-10fi+4(A6); copy coeff */
- *(*codeBlock+codeIndex-6) = 0x2D68;
- *(*codeBlock+codeIndex-5) = offset+4;
- *(*codeBlock+codeIndex-4) = -10*frameIndex+4;
- /* move.w off+8(A0),-10fi+8(A6); copy coeff */
- *(*codeBlock+codeIndex-3) = 0x3D68;
- *(*codeBlock+codeIndex-2) = offset+8;
- *(*codeBlock+codeIndex-1) = -10*frameIndex+8;
- } else if (operand == CONST_OPERAND) {
- codeIndex += 11;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l #__,-10fi(A6); frame <- const */
- *(*codeBlock+codeIndex-11) = 0x2D7C;
- *(*codeBlock+codeIndex-10) = *((int *) numPtr);
- *(*codeBlock+codeIndex-9) = *((int *) numPtr+1);
- *(*codeBlock+codeIndex-8) = -10*frameIndex;
- /* move.l #__,-10fi+4(A6) */
- *(*codeBlock+codeIndex-7) = 0x2D7C;
- *(*codeBlock+codeIndex-6) = *((int *) numPtr+2);
- *(*codeBlock+codeIndex-5) = *((int *) numPtr+3);
- *(*codeBlock+codeIndex-4) = -10*frameIndex+4;
- /* move.w #__,-10fi+8(A6) */
- *(*codeBlock+codeIndex-3) = 0x3D7C;
- *(*codeBlock+codeIndex-2) = *((int *) numPtr+4);
- *(*codeBlock+codeIndex-1) = -10*frameIndex+8;
- } else return miscErr;
- return 0;
- }
-
- /* write code for unary function, operand in stack frame */
- int UnOpCode(int operation)
- {
- if (!frameIndex) return miscErr;
- if ((operation&0x0F00)==FP68K || (operation&0x0F00)==ELEMS68K) {
- /* SANE func */
- codeIndex += 5;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* pea.l -10fi(A6); push operand_adr */
- *(*codeBlock+codeIndex-5) = 0x486E;
- *(*codeBlock+codeIndex-4) = -10*frameIndex;
- /* move.w opword, -(A7); push SANE opword */
- *(*codeBlock+codeIndex-3) = 0x3F3C;
- *(*codeBlock+codeIndex-2) = operation&0x00FF;
- if ((operation&0x0F00) == FP68K)
- *(*codeBlock+codeIndex-1)=0xA9EB;/* _Pack4 */
- else if ((operation&0x0F00) == ELEMS68K)
- *(*codeBlock+codeIndex-1)=0xA9EC;/* _Pack5*/
- else return miscErr;
- } else if ((operation&0x0F00) == CUSTOM) {
- /* custom unary function */
- codeIndex += 14;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l -10fi+6(A6),-(A7); push operand */
- *(*codeBlock+codeIndex-14) = 0x2F2E;
- *(*codeBlock+codeIndex-13) = -10*frameIndex+6;
- /* move.l -10fi+2(A6),-(A7) */
- *(*codeBlock+codeIndex-12) = 0x2F2E;
- *(*codeBlock+codeIndex-11) = -10*frameIndex+2;
- /* move.w -10fi(A6),-(A7) */
- *(*codeBlock+codeIndex-10) = 0x3F2E;
- *(*codeBlock+codeIndex-9) = -10*frameIndex;
- /* pea.l -10fi(A6); push result adr */
- *(*codeBlock+codeIndex-8) = 0x486E;
- *(*codeBlock+codeIndex-7) = -10*frameIndex;
- /* move.l #__,A0; A0 <- func_adr */
- *(*codeBlock+codeIndex-6) = 0x207C;
- *(*codeBlock+codeIndex-5) = HiWord((long) CFPtr[operation&0x00FF]);
- *(*codeBlock+codeIndex-4) = LoWord((long) CFPtr[operation&0x00FF]);
- /* jsr (A0); jump to func */
- *(*codeBlock+codeIndex-3) = 0x4E90;
- /* lea.l 14(A7),A7; reset stack ptr */
- *(*codeBlock+codeIndex-2) = 0x4FEF;
- *(*codeBlock+codeIndex-1) = 0x000E;
- } else return miscErr;
- return 0;
- }
-
- /* set up binary operation code - only destination operand in stack frame */
- int BinOpCode1(int operation, int operand, int offset)
- {
- if (frameIndex < 1) return miscErr;
- if (operand == X_OPERAND) {
- codeIndex += 2;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* pea.l 12(A6); push x_adr */
- *(*codeBlock+codeIndex-2) = 0x486E;
- *(*codeBlock+codeIndex-1) = 0x000C;
- } else if (operand == COEFF_OPERAND) {
- codeIndex += 2;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l 22(A6),A0; A0 <- coeff base adr */
- *(*codeBlock+codeIndex-2) = 0x206E;
- *(*codeBlock+codeIndex-1) = 0x0016;
- if (offset) {
- codeIndex += 2;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* pea.l off(A0); push coeff_adr */
- *(*codeBlock+codeIndex-2) = 0x4868;
- *(*codeBlock+codeIndex-1) = offset;
- } else {
- codeIndex++;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* pea.l (A0); push coeff_adr */
- *(*codeBlock+codeIndex-1) = 0x4850;
- }
- } else return miscErr;
- codeIndex += 5;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* pea.l -10fi(A6); push dest_adr */
- *(*codeBlock+codeIndex-5) = 0x486E;
- *(*codeBlock+codeIndex-4) = -10*frameIndex;
- if ((operation&0xF000) == EXPONENT) {
- /* move.w FXPWRY,-(A7); push FXPWRY */
- *(*codeBlock+codeIndex-3) = 0x3F3C;
- *(*codeBlock+codeIndex-2) = FXPWRY;
- *(*codeBlock+codeIndex-1)=0xA9EC;/* _Pack5 */
- } else if ((operation&0x0F00) == FP68K) {
- /* move.w opword,-(A7); push SANE opword */
- *(*codeBlock+codeIndex-3) = 0x3F3C;
- *(*codeBlock+codeIndex-2) = operation&0x00FF;
- *(*codeBlock+codeIndex-1)=0xA9EB;/* _Pack4 */
- } else return miscErr;
- return 0;
- }
-
- /* set up binary operation code - both operands are in stack frame */
- int BinOpCode2(int operation)
- {
- if (frameIndex < 2) return miscErr;
- codeIndex += 7;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* pea.l -10fi(A6); push src operand */
- *(*codeBlock+codeIndex-7) = 0x486E;
- *(*codeBlock+codeIndex-6) = -10*frameIndex;
- /* pea.l -10fi+10(A6); push dest operand */
- *(*codeBlock+codeIndex-5) = 0x486E;
- *(*codeBlock+codeIndex-4) = -10*frameIndex+10;
- if ((operation&0xF000) == EXPONENT) {
- /* move.w FXPWRY,-(A7); push FXWPRY */
- *(*codeBlock+codeIndex-3) = 0x3F3C;
- *(*codeBlock+codeIndex-2) = FXPWRY;
- *(*codeBlock+codeIndex-1)=0xA9EC;/* _Pack5 */
- } else if ((operation&0x0F00) == FP68K) {
- /* move.w opword,-(A7); push SANE opword */
- *(*codeBlock+codeIndex-3) = 0x3F3C;
- *(*codeBlock+codeIndex-2) = operation&0x00FF;
- *(*codeBlock+codeIndex-1)=0xA9EB;/* _Pack4 */
- } else return miscErr;
- frameIndex--; /* decrement frame position */
- return 0;
- }
-
- /* copy operand to address specified by 8(A6) */
- int ReturnCode1(int operand, int offset, extended *numPtr)
- {
- if (operand == CONST_OPERAND) {
- codeIndex += 10;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l 8(A6),A0; A0 <- result_adr */
- *(*codeBlock+codeIndex-10) = 0x206E;
- *(*codeBlock+codeIndex-9) = 0x0008;
- /* move.l #__,(A0)+; copy const to result_adr */
- *(*codeBlock+codeIndex-8) = 0x20FC;
- *(*codeBlock+codeIndex-7) = *((int *) numPtr);
- *(*codeBlock+codeIndex-6) = *((int *) numPtr+1);
- /* move.l #__,(A0)+ */
- *(*codeBlock+codeIndex-5) = 0x20FC;
- *(*codeBlock+codeIndex-4) = *((int *) numPtr+2);
- *(*codeBlock+codeIndex-3) = *((int *) numPtr+3);
- /* move.w #__,(A0)+ */
- *(*codeBlock+codeIndex-2) = 0x30FC;
- *(*codeBlock+codeIndex-1) = *((int *) numPtr+4);
- return 0;
- } else if (operand == X_OPERAND) {
- codeIndex += 4;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l 8(A6),A0; A0 <- result_adr */
- *(*codeBlock+codeIndex-4) = 0x206E;
- *(*codeBlock+codeIndex-3) = 0x0008;
- /* lea.l 12(A6),A1; A1 <- x_adr */
- *(*codeBlock+codeIndex-2) = 0x43EE;
- *(*codeBlock+codeIndex-1) = 0x000C;
- } else if (operand == COEFF_OPERAND) {
- codeIndex += 4;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l 8(A6),A0; A0 <- result_adr */
- *(*codeBlock+codeIndex-4) = 0x206E;
- *(*codeBlock+codeIndex-3) = 0x0008;
- /* move.l 22(A6),A1; A1 <- coeff base Adr */
- *(*codeBlock+codeIndex-2) = 0x226E;
- *(*codeBlock+codeIndex-1) = 0x0016;
- if (offset) {
- codeIndex += 2;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* lea.l off(A1),A1; A1 <- coeff_adr */
- *(*codeBlock+codeIndex-2) = 0x43E9;
- *(*codeBlock+codeIndex-1) = offset;
- }
- } else return miscErr;
- codeIndex += 3;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l (A1)+,(A0)+; copy operand to result */
- *(*codeBlock+codeIndex-3) = 0x20D9;
- /* move.l (A1)+,(A0)+ */
- *(*codeBlock+codeIndex-2) = 0x20D9;
- /* move.w (A1)+,(A0)+ */
- *(*codeBlock+codeIndex-1) = 0x30D9;
- return 0;
- }
-
- /* copy result to address in 8(A6) */
- int ReturnCode2(void)
- {
- codeIndex += 7;
- SetHandleSize(codeBlock, 2*codeIndex);
- if (MemError()) return memoryErr;
- /* move.l 8(A6),A0; A0 <- result_adr */
- *(*codeBlock+codeIndex-7) = 0x206E;
- *(*codeBlock+codeIndex-6) = 0x0008;
- /* lea.l -10(A6),A1; A1 <- frame_adr */
- *(*codeBlock+codeIndex-5) = 0x43EE;
- *(*codeBlock+codeIndex-4) = 0xFFF6;
- /* move.l (A1)+,(A0)+; copy frame to result */
- *(*codeBlock+codeIndex-3) = 0x20D9;
- /* move.l (A1)+,(A0)+ */
- *(*codeBlock+codeIndex-2) = 0x20D9;
- /* move.w (A1)+,(A0)+ */
- *(*codeBlock+codeIndex-1) = 0x30D9;
- return 0;
- }
-
-